package com.ee.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ee.bean.User;
import com.ee.dao.UserDao;
import com.ee.service.UserService;
import com.ee.util.Md5Util;
@Component("userService")
public class UserServiceImpl implements UserService {
	private UserDao userDao;
	@Override
	public void add(User user) {
		userDao.saveUser(user);
	}

	@Override
	public void update(User user) {
		userDao.update(user);
	}

	@Override
	public void delete(User user) {
		userDao.deleteUser(user);
	}

	@Override
	public User getUserById(int id) {
		return userDao.findUserById(id);
	}

	@Override
	public User checkLogin(String account, String password) {
		List<User> users = userDao.getUserByNamePwd(account, Md5Util.md5(password));
		if(users.size() > 0){
			return users.get(0);
		}
		return null;
	}

	public UserDao getUserDao() {
		return userDao;
	}
	@Resource
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public boolean checkAccount(String account) {
		// TODO Auto-generated method stub
		List<User> users = userDao.findUserByName(account);
		if(users.size() > 0){
			return true;
		}
		return false;
	}

	@Override
	public List<User> findOperators() {
		return userDao.findOperators();
	}

	@Override
	public List<User> findUsers() {
		
		return userDao.findAllUsers();
	}
	
	

}
